<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title></title>
	<link rel="stylesheet" type="text/css" href="../../../bangnuo/admin/layui/css/layui.css">
	<script type="text/javascript" src="../../../bangnuo/admin/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="../../../bangnuo/admin/layui/layui.js"></script>
</head>

<style>
	#wrappertable {
		width: 100%;
		height: 100%;
		margin: 0;
		padding: 0;
		border: none;
		text-align: center;
	}

	.th{
		background-color: #D9EDF7;
		height: 50px;
	}
	.td{
		background-color: #F0F0F0;
		height: 50px;
	}
	.tv{
		background-color: #00F7DE;
		height: 50px;
		margin-right: ;
	}

</style>
<body style="margin: 10px; padding: 10px; width: 100%;">
<div>
	<div id="agentUp" style="width: 100%; height: 50px; font-size: 20px; font-weight: bold; color: #007DDB;">
		某某代理商
	</div>
	<hr />
	<div style="padding: 15px; display: none;" class="LAY-agent-list-box">
		<blockquote class="layui-elem-quote">
			<div class="LAY-agent-list">
			</div>
		</blockquote>
	</div>
	<div class="layui-tab">
		<ul class="layui-tab-title">
			<li class="layui-this">按照拥总调整</li>
			<li>按照商户明细调整</li>
		</ul>
		<div class="layui-tab-content">
			<div class="layui-tab-item layui-show">
				<table id="wrappertable"></table>
				<button class="layui-btn" onclick="actions()" style="margin: 10px;">确认生成结拥数据</button>
			</div>
			<div class="layui-tab-item">内容2</div>
		</div>
	</div>
</div>
</div>
</body>
<script>

	function getQueryVariable(variable){
		var query = window.location.search.substring(1);
		var vars = query.split("&");
		for (var i=0;i<vars.length;i++) {
			var pair = vars[i].split("=");
			if(pair[0] == variable){return pair[1];}
		}
		return(false);
	}

    var formData1 = {};

	//注意：选项卡 依赖 element 模块，否则无法进行功能性操作
	layui.use('element', function() {
		var element = layui.element;
		$(document).ready(function() {
			$.ajax({
				type: 'GET',
				url: '/commission/findMonthById/'+getQueryVariable("id"),
				dataType: "JSON",
				success: function(res) {
				    formData1 = res.object;
				    var arr = new Array();
				    var objectMap = {
				        "aliPay":"支付宝",
						"order":"",
						"week":res.object.aliPay/100,
						"agent":"",
                        minagent:""
					};

                    var objectMap1 = {
                        "aliPay":"微信",
                        "order":"",
                        "week":res.object.wxPay/100,
                        "agent":"",
                        minagent:""
                    };

                    var objectMap2 = {
                        "aliPay":"建联",
                        "order":"",
                        "week":res.object.thirdParty/100,
                        "agent":"",
                        minagent:""
                    };

				    arr.push(objectMap);
                    arr.push(objectMap1);
                    arr.push(objectMap2);
                    console.log("bbbbbb",arr);
					var test = '<tr><th class="th">通道</th><th class="th">有效交易金额（元）</th><th class="th">当前返佣（元）</th><th class="th">返佣调整成（元）</th><th class="th">代理低价</th><th class="th">我的低价</th></tr>';
					var divshow = $("#wrappertable");
					for (var i = 0; i < arr.length; i++) {
						test += '<tr><td class="td">' + arr[i].aliPay + '</td><td class="td">' + arr[i].order +
								'</td><td class="td">' + arr[i].week + '</td><td class="td">' + '<input style="width: 200px; height: 30px;" type="text" name="week" id="name'+ i+'" value="'+arr[i].week+'" />' +
								'</td><td class="td">' + arr[i].agent + '</td><td class="td">' + arr[i].minagent +
								'</td></tr>';
						test += "";
					}
					test += "<tr><td class='td'>备注</td><td class='td' colspan='5'><input  type='text' style=' float:left; width: 300px;height: 30px;'  name = 'desc' id = 'desc' value='' /></td></tr>"
					divshow.html(test);
				}
			});
		});
	});
</script>
<script type="text/javascript">
	function actions(){
        layui.use('form', function () {
            var form = layui.form;
            formData1.aliPay = $("name0").val() * 100;
            formData1.wxPay = $("name1").val() * 100;
            formData1.thirdParty = $("name2").val() * 100;
            formData1.remark = $("desc").val();
            $.ajax({
                type: 'POST',
                url: "/commission/updateMonthById/" + getQueryVariable("id"),
                dataType: 'JSON',
                data: JSON.stringify(formData1),
                contentType: "application/json;charset=UTF-8",
                success: function (data) {
                    if (data.success == true) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        console.log("index值", index)
                        close();
                    } else {
                        layer.msg("生成失败");
                    }
                }
            });
        });



		/* alert($("#name0").val());
        alert($("#name1").val());
        alert($("#name2").val());
        alert($("#desc").val()); */
	}
</script>
</html>
